package upnp.toy;

import java.util.HashMap;

import org.osgi.service.upnp.UPnPAction;
import org.osgi.service.upnp.UPnPService;
import org.osgi.service.upnp.UPnPStateVariable;

public class ToyService implements UPnPService{

	final static private String SERVICE_ID = "urn:schemas-upnp-org:serviceId:toyService:1";
	final static private String SERVICE_TYPE = "urn:schemas-upnp-org:service:toy:" 
		+ ToyService.VERSION;
	final static private String VERSION = "1";

	private UPnPStateVariable sampleVariable;
	private UPnPStateVariable[] states;
	private HashMap actions = new HashMap();
	
	
	public ToyService(){
		
		this.sampleVariable = new SampleVariable();
		this.states = new UPnPStateVariable[]{sampleVariable};		
		UPnPAction setSampleVariable= new SetVariableAction(sampleVariable);
		this.actions.put(setSampleVariable.getName(),setSampleVariable);
		
	}
	
	
	
	public UPnPAction getAction(String name) {
		return (UPnPAction)actions.get(name);
	}

	
	public UPnPAction[] getActions() {
		return (UPnPAction[])(actions.values()).toArray(new UPnPAction[]{});
	}

	
	public String getId() {
		return SERVICE_ID;
	}

	
	public UPnPStateVariable getStateVariable(String name) {
		if (name.equals("SampleVariable"))
			return sampleVariable;
		else return null;
	}

	
	public UPnPStateVariable[] getStateVariables() {
		return states;
	}

	
	public String getType() {
		return SERVICE_TYPE;
	}

	
	public String getVersion() {
		return VERSION;
	}

}
